#pragma once

#include "sfc_rom.h"
#include "sfc_code.h"

struct sfc_famicom;
typedef struct sfc_famicom sfc_famicom_t;

// 模拟器接口
typedef struct {
	sfc_ecode(*load_rom)(void* args, sfc_rom_info_t* info);
	sfc_ecode(*free_rom)(void* args, sfc_rom_info_t* info);
} sfc_interface_t;

// mapper 接口
typedef struct {
	sfc_ecode(*reset)(sfc_famicom_t*);
} sfc_mapper_t;

// 模拟器主体
struct sfc_famicom{
	void*				argument;
	sfc_interface_t		interfaces;
	sfc_mapper_t		mapper;
	sfc_rom_info_t		rom_info;
	uint8_t				main_memory[2 * 1024];		// CPU insternal memory
	uint8_t				save_memory[8 * 1024];		// save memory / work memory
	uint8_t*			prg_banks[0x10000 >> 13];	// PRG-ROM， 存在 sfc_rom_info_t 里，这里只记录起始地址
};

sfc_ecode sfc_famicom_init(sfc_famicom_t* famicom, void* argument, const sfc_interface_t* interfaces);
void sfc_famicom_uninit(sfc_famicom_t*);